def hanoi(n, x='A', y='B', z='C'):
    if n < 1:
        print('请输入一个大于等于1的数！')
    elif n == 1:
        print('从', x, '移动到', z)
    else:
        hanoi(n - 1, x, z, y)
        print('从', x, '移动到', z)
        hanoi(n - 1, y, x, z)


if __name__ == '__main__':
    try:
        n = int(input('请输入汉诺塔的层数... > '))
        hanoi(n)
        print('总共移动了', 2 ** n - 1, '步\n')
    except ValueError:
        print("请输入一个整数！")
    except KeyboardInterrupt:
        print("---进程被打断，移动未完成---\n")
    input("按下回车继续...")
